﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading.Tasks;

namespace Civilisation_code.PVCarte
{
    /// <summary>
    /// Poids-mouche pour la construction des images d'unités
    /// Singleton
    /// </summary>
    class Fabrique_Img_Unite
    {
        /// <summary>
        /// Instance de la classe 
        /// Singleton
        /// </summary>
        public static readonly Fabrique_Img_Unite FABRIQUE_IMG_UNITE = new Fabrique_Img_Unite();

        /// <summary>
        /// Hastables contenant tous les ImageBrush
        /// </summary>
        private Hashtable instances;

        /// <summary>
        /// Constructeur privé
        /// </summary>
        private Fabrique_Img_Unite()
        {
            instances = new Hashtable();
        }

        /// <summary>
        /// Méthode permettant d'obtenir l'ImageBrush correspondant à l'unité
        /// </summary>
        /// <param name="nom_ressource">Nom de civilisation</param>
        /// <param name="bonus">Nom de l'unité</param>
        /// <returns>L'ImageBrush correspondant</returns>
        public ImageBrush obtenirUnite(string nom_civilisation, string unite)
        {
            if (!instances.ContainsKey(nom_civilisation + unite))
            {
                creationUnite(nom_civilisation + unite);
            }
            return (ImageBrush)instances[nom_civilisation + unite];
        }

        /// <summary>
        /// Création de l'ImageBrush
        /// </summary>
        /// <param name="nom_ressource">Nom de la civilisation + type de l'unité</param>
        void creationUnite(string unite)
        {
            ImageBrush im = new ImageBrush();
            switch (unite)
            {
                case "INFODirecteur":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.INFODirecteur.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(unite, im);
                    break;
                case "INFOEnseignant":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.INFOEnseignant.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(unite, im);
                    break;
                case "INFOEtudiant":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.INFOEtudiant.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(unite, im);
                    break;
                case "EIIDirecteur":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.EIIDirecteur.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(unite, im);
                    break;
                case "EIIEnseignant":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.EIIEnseignant.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(unite, im);
                    break;
                case "EIIEtudiant":
                    im.ImageSource = (System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Civilisation.Properties.Resources.EIIEtudiant.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                    instances.Add(unite, im);
                    break;
            }
        }
    }
}

